package main

import (
	"fmt"
	"math/rand"
	"time"
)

func main() {
	rand.Seed(time.Now().UnixNano())
	//生成一个大于3个字符的随机字符串
	randomString := generateRandomString(4 + rand.Intn(6))
	fmt.Println("随机生成的字符串", randomString)

	//将字符穿逆序打印
	reversedString := reverseString(randomString)
	fmt.Println("逆序打印的字符串", reversedString)

}

// 生成自定长度的随机小写字母字串
func generateRandomString(length int) string {
	var letters = []rune("abcdefghijklmnopqrstuvwxyz")
	result := make([]rune, length)
	for i := range result {
		result[i] = letters[rand.Intn(len(letters))]
	}
	return string(result)
}

// 将字符串逆序

func reverseString(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}
